#include "newspaper/newspapermanager.h"
#include "model/appmainmodel.h"
#include "newspaper/newspapermanager.h"
#include "model/sourcemodel.h"
#include "model/articlemodel.h"
#include "model/categorymodel.h"
#include "applicationinfo.h"


#include <QApplication>
#include <QtQuick/QQuickView>
#include <QtQml/QQmlEngine>
#include <QtQml/QQmlContext>
#include <QtQuick/QQuickItem>
#include <QUrl>
#include <QQmlApplicationEngine>

static QObject *systeminfo_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
{
    Q_UNUSED(engine)
    Q_UNUSED(scriptEngine)

    return new ApplicationInfo();
}

void qmlRegister()
{

    qmlRegisterType<SourceListModel>("org.qtproject.znews_qt", 1, 0, "SourceListModel");
    qmlRegisterType<CategoryListModel>("org.qtproject.znews_qt", 1, 0, "CategoryListModel");
    qmlRegisterType<ArticleListModel>("org.qtproject.znews_qt", 1, 0, "ArticleListModel");
    qmlRegisterType<ContentModel>("org.qtproject.znews_qt", 1, 0, "ContentModel");
    qmlRegisterSingletonType<ApplicationInfo>("org.qtproject.znews_qt", 1, 0, "ApplicationInfo", systeminfo_provider);

}

int main(int argc, char *argv[])
{
    qmlRegister();

    /* longdh test */
    QApplication app(argc, argv);
    NewspaperManager::instance(&app);

    QQmlApplicationEngine engine(QUrl("qrc:/gui/MainWindows.qml"));
    QObject *topLevel = engine.rootObjects().value(0);
    QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel);
    if ( !window ) {
        qWarning("Error: Your root item has to be a Window.");
        return -1;
    }
    window->show();
    return app.exec();

}
